<?php
// $image=['.png','.jpg','.gif'];
// if(!empty($_POST)){
//     $name = $_FILES['image']['name'];
//     $key=strrchr($key,'.');
//     if(in_array($key,$image)){
//         if($_FILES['image']['error']==0){
//             $path=uniqid('user').rand(100,500).$_FILES['image']['tmp_name'];
//             move_uploaded_file($_FILES['image']['tmp_name'],'./upload/'.$path);
//             echo '上传成功';
//         }else{
//             echo "上传失败";
//         }
//     }else{
//         echo "文件格式错误";
//     }
// }
$allow=array('image/jpeg','image/png','image/gif');
$info=finfo_open(FILEINFO_MIME_TYPE);
$min=finfo_file($info,$_FILES['image']['tmp_name']);
if(in_array($min,$allow)){
    if($_FILES['image']['error']==0){
                     $path=uniqid('user').rand(100,500).$_FILES['image']['tmp_name'];
                     move_uploaded_file($_FILES['image']['tmp_name'],'./upload/'.$path);
                     echo '上传成功';
                 }else{
                     echo "上传失败";
                }
            }else{
                 echo "文件格式错误";
            }
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="" method="post" enctype="multipart/form-data">
    <input type="file" name="image" id="">
    <input type="submit" name="sub" value="上传">
    </form>
</body>
</html>